#include <iostream>
#include "queue.h"

int ptri(int n);
/*
int ptri(int n)
{
    int i, j;
    int s, t;
    Queue<int> q;

    if (n <= 0)
	return -1;

    q.MakeEmpty();
    q.EnQueue(1);
    q.EnQueue(1);
    
    s = 0;
    for (i = 0; i < n; i++) {
	q.EnQueue(0);
	for (j = 0; j <= i + 2; j++) {
	    q.GetFront(t);
	    q.DeQueue();
	    if (j < i + 2)
		fprintf(stdout, "%d\t", t);
	    q.EnQueue(s+t);
	    s = t;
	}
	fprintf(stdout, "\n");
    }

    return 0;
}
*/

int main(int argc, char *argv[])
{
    int n;
    
    if (argc < 2) {
	fprintf(stderr, "Usage: %s n(levels of pascal's triangle to print)\n", argv[0]);
	exit(1);
    }
    n = atoi(argv[1]);

    if (ptri(n) < 0) {
	fprintf(stderr, "print pascal's triangle failed\n");
	exit(1);
    }

    return 0;
}

int ptri(int n)
{
    int i, j, s, t;
    Queue<int> qi;
    
    qi.EnQueue(1); qi.EnQueue(1);
    s = 0;
    for (i = 1; i <= n; i++)
    {
	// per level
	// add the trailing 0 in previous level
	qi.EnQueue(0);
	
	for (j=1; j <= i+2; j++)
	{

	    qi.GetFront(t);
	    qi.DeQueue();
	    if (j != i+2)
	    {	// if not the trailing 0
		fprintf(stdout, "%d\t", t);
	    }
	    qi.EnQueue(s+t);
	    s = t;
	}
	fprintf(stdout, "\n");
    }

    return 0;
}
